package test.demo.controller;

import com.zhj.helloframework.core.annotation.Controller;
import com.zhj.helloframework.injection.annotation.Autowired;
import com.zhj.helloframework.mvc.annotation.RequestMapping;
import com.zhj.helloframework.mvc.annotation.RequestParam;
import com.zhj.helloframework.mvc.annotation.ResponseBody;
import com.zhj.helloframework.mvc.type.ModelAndView;
import com.zhj.helloframework.mvc.type.RequestMethod;
import test.demo.pojo.Book;
import test.demo.service.BookService;

import java.util.List;

/**
 * @Author: zhj
 * @Description:
 * @Date: 2021/11/17 13:51
 * @Version: 1.0
 */
@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @ResponseBody
    public List<Book> getAllBooksInfo() {
        return bookService.getAllBooksInfo();
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ModelAndView addBook(@RequestParam(value = "bookName") String bookName, @RequestParam(value = "author") String author) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView("/addSuccess.jsp")
                .addViewData("bookName",bookName)
                .addViewData("author",author);
        return modelAndView;
    }
}
